// import axois from 'axios'
import axios from './axios.ts'

// 登录接口
export function Login(data:object):any{
  return new Promise((resolve, reject) => {
    axios({
      method:'post',
      url: 'api/login/',
      data
    }).then(res => {
      resolve(res.data)
    }).catch(() => {
      window.$message.error("登录接口异常")
      reject(new Error("登录接口异常"))
    })
  })
}

// 获取全部用户接口
export function GetAllUser():any{
  return new Promise((resolve, reject) => {
    axios({
      method:'get',
      url: 'api/get_all_user/',
    }).then(res => {
      resolve(res.data)
    }).catch(() => {
      window.$message.error("接口异常")
      reject(new Error("接口异常"))
    })
  })
}

// 设置管理员用户
export function SetSuperUser(data:object):any{
  return new Promise((resolve, reject) => {
    axios({
      method:'post',
      url: 'api/set_super_user/',
      data
    }).then(res => {
      resolve(res.data)
    }).catch(() => {
      window.$message.error("接口异常")
      reject(new Error("接口异常"))
    })
  })
}

// 移除管理员用户
export function RemoveSuperUser(data:object):any{
  return new Promise((resolve, reject) => {
    axios({
      method:'post',
      url: 'api/remove_super_user/',
      data
    }).then(res => {
      resolve(res.data)
    }).catch(() => {
      window.$message.error("接口异常")
      reject(new Error("接口异常"))
    })
  })
}

// 获取全部漫画接口
export function GetAllCartoon():any{
  return new Promise((resolve, reject) => {
    axios({
      method:'get',
      url: 'api/local_get_cartoon/',
    }).then(res => {
      resolve(res.data)
    }).catch(() => {
      window.$message.error("接口异常")
      reject(new Error("接口异常"))
    })
  })
}

// 获取分类漫画接口
export function GetTypeCartoon(data: object):any{
  return new Promise((resolve, reject) => {
    axios({
      method:'post',
      url: 'api/get_recommend_cartoon/',
      data
    }).then(res => {
      resolve(res.data)
    }).catch(() => {
      window.$message.error("接口异常")
      reject(new Error("接口异常"))
    })
  })
}

// 添加分类漫画
export function SetTypeCartoon(data: object):any{
  return new Promise((resolve, reject) => {
    axios({
      method:'post',
      url: 'api/add_recommend_cartoon/',
      data
    }).then(res => {
      resolve(res.data)
    }).catch(() => {
      window.$message.error("接口异常")
      reject(new Error("接口异常"))
    })
  })
}

// 移除分类漫画
export function RemoveTypeCartoon(data: object):any{
  return new Promise((resolve, reject) => {
    axios({
      method:'post',
      url: 'api/remove_recommend_cartoon/',
      data
    }).then(res => {
      resolve(res.data)
    }).catch(() => {
      window.$message.error("接口异常")
      reject(new Error("接口异常"))
    })
  })
}

// 获取所有文章接口
export function GetAllEssay():any{
  return new Promise((resolve, reject) => {
    axios({
      method:'get',
      url: 'api/get_all_essay/',
    }).then(res => {
      resolve(res.data)
    }).catch(() => {
      window.$message.error("接口异常")
      reject(new Error("接口异常"))
    })
  })
}

// 获取文章评论接口
export function GetEssayComment(data: object):any{
  return new Promise((resolve, reject) => {
    axios({
      method:'post',
      url: 'api/get_essay_comment/',
      data
    }).then(res => {
      resolve(res.data)
    }).catch(() => {
      window.$message.error("接口异常")
      reject(new Error("接口异常"))
    })
  })
}

// 删除文章接口
export function DeleteEssay(data: object):any{
  return new Promise((resolve, reject) => {
    axios({
      method:'post',
      url: 'api/delete_essay/',
      data
    }).then(res => {
      resolve(res.data)
    }).catch(() => {
      window.$message.error("接口异常")
      reject(new Error("接口异常"))
    })
  })
}

// 删除文章评论接口
export function DeleteComment(data: object):any{
  return new Promise((resolve, reject) => {
    axios({
      method:'post',
      url: 'api/delete_comment/',
      data
    }).then(res => {
      resolve(res.data)
    }).catch(() => {
      window.$message.error("接口异常")
      reject(new Error("接口异常"))
    })
  })
}
